package cn.johnyu.service.impl;

import cn.johnyu.client.AccountClient;
import cn.johnyu.client.ProductClient;
import cn.johnyu.domain.Order;
import cn.johnyu.mapper.OrderMapper;
import cn.johnyu.pojo.OrderPo;
import cn.johnyu.service.OrderService;
import org.example.commons.dto.AccountDto;
import org.example.commons.dto.ProductDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired private OrderMapper orderMapper;
    @Autowired private ProductClient productClient;
    @Autowired private AccountClient accountClient;
    @Override
    public Order loadOrder(int id) {

        OrderPo orderPo = orderMapper.loadOrder(id);// 查询订单id

        ProductDto dto = productClient.loadProducts(orderPo.getPid()); //根据订单id查询产品id
        AccountDto accountDto = accountClient.loadAccount(orderPo.getAid());



        return new Order().setId(orderPo.getId()).setAmount(orderPo.getAmount())
                .setProduct(dto).setAccount(accountDto);
    }
}
